package panel.common;

import frame.Chat;
import frame.FindUser;
import frame.Home;
import function.SendMessage;
import global.Const;
import global.PublciVariable;
import other.DButton;
import other.HeadImage;

import javax.swing.*;
import java.awt.*;

public class UserInfo extends JPanel {
    JLabel name = new JLabel("undefined");
    JLabel sign = new JLabel("undefined");
    HeadImage headImage = new HeadImage("undefined");

    public boolean allowStrangerChat = false;
    public String username = "undefined";
    public String userSign = "undefined";


    public UserInfo() {

        setSize(400, 200);
        setOpaque(false);
        setLayout(null);

        // 头像
        headImage.setBounds(0, 0, 100);

        // 用户名
        name.setOpaque(true);
        name.setHorizontalAlignment(SwingConstants.CENTER);
        name.setBackground(new Color(0, 0, 0, 80));
        name.setBounds(100, 0, 300, 36);
        name.setFont(new Font("宋体", Font.BOLD, 40));
        name.setForeground(Color.white);

        // 个性签名
        sign.setOpaque(true);
        sign.setHorizontalAlignment(SwingConstants.CENTER);
        sign.setVerticalAlignment(SwingConstants.CENTER);
        sign.setBackground(new Color(0, 0, 0, 80));
        sign.setBounds(100, 36, 300, 64);
        sign.setFont(new Font("宋体", Font.BOLD, 20));
        sign.setForeground(Color.gray);

        // 添加组件
        add(headImage);
        add(name);
        add(sign);
        setVisible(false);
    }

    public void open(String username, String userSign, boolean allowStrangerChat) {
        this.username = (username == null || username.isEmpty()) ? "undefined" : username;
        this.userSign = (userSign == null || userSign.isEmpty()) ? "undefined" : userSign;
        this.allowStrangerChat = allowStrangerChat;

        name.setText(username);
        sign.setText(userSign);
        headImage.setName(username);

        setVisible(true);
    }

    public void close() {
        setVisible(false);
    }
}
